package com.sena.base;


import java.io.Serializable;
import java.util.List;

/**
 * @author seven
 * @create 2018-11-06 13:42
 **/

public class BasePage<T> implements Serializable {

    private static final long serialVersionUID = -7020023193417662078L;
    /**
     * 页码，从1开始
     */
    private int pageNum;
    /**
     * 页面大小
     */
    private int pageSize;
    /**
     * 总数
     */
    private long total;
    /**
     * 总页数
     */
    private int pages;

    private List<T> list;

    public BasePage() {

    }

    public BasePage(List<T> list, int pageNum, int pageSize, long total) {
        this.list = list;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
    }

    public void caculate() {
        if (getPageSize() == 0) {
            pages = 0;
            return;
        }
        if (total % getPageSize() == 0) {
            pages = (int) (total / getPageSize());
        } else {
            pages = (int) (total / getPageSize() + 1);
        }
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPages() {
        caculate();
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
